package com.eve;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;

@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker                  // 服务熔断
public class HystrixApplication {

	public static void main(String[] args) {
		SpringApplication.run(HystrixApplication.class, args);
	}
	
	/**
	 * 此配置是为了服务监控而配置，与服务器本身无关，springcloud升级后的坑
	 * ServletRegistrationBean因为springboot的默认路径不是"/hystrix.stream"，
	 * 只要在自己项目里配置了下面的servlet就可以了
	 */
	@Bean
	public ServletRegistrationBean getServlet() {
		HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
		ServletRegistrationBean registrationServlet = new ServletRegistrationBean(streamServlet);
		registrationServlet.setLoadOnStartup(1);
		registrationServlet.addUrlMappings("/hystrix.stream");
		registrationServlet.setName("HystrixMetricStreamServlet");
		return registrationServlet;
	}
	
}
